import Base from "./base"
import MediaComponent from "./component/media/single";
import MediaGroupComponent from "./component/media/group";
import MediaShowcaseComponent from "./component/media/showcase";
import TextComponent from "./component/text";
import LibMedia from "./component/media/lib";

// media Update Code ok

// 创意
class Creative extends Base {
  name: string = '创意';
  mediaComponent: Array<MediaGroupComponent | MediaComponent | MediaShowcaseComponent> = [];
  textComponent: Array<TextComponent> = [];
  // 只在 creativor.unSpecifiedForm 时启用
  libMedia: LibMedia = new LibMedia({});

  derivedCreativeSwitch: 1 | 0 = 0;

  constructor(options: any) {
    super();
    this.init(options);
    return this;
  }

}

// 创意组
class CreativeGroup extends Base {

  name: string = '创意组';
  creative: Array<Creative> = []



}




// 广告创意
class Creativor extends Base {
  // 投放模式
  deliveryMode: 'DELIVERY_MODE_COMPONENT' | 'DELIVERY_MODE_CUSTOMIZE' = 'DELIVERY_MODE_CUSTOMIZE';
  // 投放模式为组件化创意时可用 指定创意形式
  specified_form: 1 | 0 = 1;
  way: 'image' | 'video' = 'image'
  // 存模版格式
  ectypeComponent: {
    text: TextComponent | undefined,
    media: Array<MediaComponent | MediaGroupComponent | LibMedia>
  } = {
      text: undefined,
      media: []
    };
  brandType: any = 3
  creativeTemplateId: any = undefined;
  // groups: Array<CreativeGroup> = [new CreativeGroup()];
  groups: Array<CreativeGroup> = [];



  // 创意详情loading
  contentLoading = false
  name = '';

  // 是否需要素材
  get hasMediaOrText() {
    return this.ectypeComponent.text || this.ectypeComponent.media.length
  }

  // 橱窗类
  get isMediaShowcase() {
    return this.creativeTemplateId == 2107 || this.creativeTemplateId == 2109;
  }
  // 是组件化创意
  get isComponentCreative() {
    return this.deliveryMode === 'DELIVERY_MODE_COMPONENT';
  }



  //  不指定创意形式
  get unSpecifiedForm() {
    return this.isComponentCreative && this.specified_form == 0;
  }

  get canuse() {
    if (!this.unSpecifiedForm) return !!this.creativeTemplateId;
    return true;
  }

  constructor(options: any) {
    super();
    this.init(options);
    return this;
  }
}

export { CreativeGroup, Creative }

export default Creativor
